package work.skc.customer_task_record;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.StrBuilder;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;

import java.nio.charset.Charset;
import java.util.Set;

/**
 * 组装SQL
 */
public class Setup2 {
    public static void main(String[] args) {
        EasyExcel.read(Setting.setup1, CustomerExcelObject.class, new Setup2List()).sheet().doRead();
    }

    public static class Setup2List implements ReadListener<CustomerExcelObject> {
        StrBuilder items = new StrBuilder();

        @Override
        public void invoke(CustomerExcelObject customerExcelObject, AnalysisContext analysisContext) {
            if (customerExcelObject.isHit()) {
                items.append(customerExcelObject.toItem());
            }
        }

        @Override
        public void doAfterAllAnalysed(AnalysisContext analysisContext) {
            String sql = String.format(Setting.insertSql, items);
            FileUtil.writeString(sql, Setting.setup2, Charset.defaultCharset());
        }
    }
}
